package com.getpebble.android.main.drawer.view;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.getpebble.android.R;
import com.getpebble.android.main.drawer.model.DrawerItem;

public class DrawerItemView extends LinearLayout {
    private ImageView mIconImageView;
    private boolean mIsSelected;
    private TextView mLabelTextView;

    public DrawerItemView(Context context) {
        this(context, null);
    }

    public DrawerItemView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public void onFinishInflate() {
        super.onFinishInflate();
        this.mLabelTextView = (TextView) findViewById(R.id.tv_item_label);
        this.mIconImageView = (ImageView) findViewById(R.id.iv_item_icon);
    }

    public DrawerItemView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        this.mLabelTextView = null;
        this.mIconImageView = null;
        this.mIsSelected = false;
    }

    public void setModel(DrawerItem drawerItem) throws IllegalArgumentException {
        if (drawerItem == null) {
            throw new IllegalArgumentException("'drawerItem' cannot be null!");
        }
        if (this.mLabelTextView != null) {
            this.mLabelTextView.setText(drawerItem.getLabel());
        }
        if (this.mIconImageView != null) {
            this.mIconImageView.setImageResource(drawerItem.getIconResourceId());
        }
    }

    public void setAsSelected(boolean isSelected) {
        this.mIsSelected = isSelected;
        if (this.mIsSelected && this.mLabelTextView != null) {
            this.mLabelTextView.setTypeface(this.mLabelTextView.getTypeface(), 1);
        } else if (!this.mIsSelected && this.mLabelTextView != null) {
            this.mLabelTextView.setTypeface(this.mLabelTextView.getTypeface(), 0);
        }
    }
}
